﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace LdCms.Web.Controllers.API.Community.V1
{
    using LdCms.EF.DbModels;
    using LdCms.Common.Extension;
    using LdCms.IBLL.Community;
    using LdCms.Web.Services;
    /// <summary>
    /// 
    /// 
    /// 
    /// </summary>
    [ApiVersion("1.0")]
    [ControllerName("community/config")]
    public class CommunityConfigController : BaseApiController
    {
        private readonly IBaseApiManager BaseApiManager;
        private readonly IHttpContextAccessor Accessor;
        private readonly IConfigService ConfigService;
        public CommunityConfigController(IBaseApiManager BaseApiManager, IHttpContextAccessor Accessor, IConfigService ConfigService) : base(BaseApiManager)
        {
            this.BaseApiManager = BaseApiManager;
            this.Accessor = Accessor;
            this.ConfigService = ConfigService;
        }
        /// <summary>
        /// 获取社区配置
        /// </summary>
        /// <param name="uuid"></param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("get")]
        public IActionResult GetConfig(string uuid)
        {
            long logId = 0;
            try
            {
                logId = BaseApiManager.SaveLogs(uuid);
                int systemId = InterfaceAccount.SystemID;
                string companyId = InterfaceAccount.CompanyID;
                var entity = ConfigService.GetConfig(systemId, companyId);
                if (entity == null)
                    return Error(logId, "system error！");
                var data = new
                {
                    name = entity.Name.IIF(),
                    title = entity.Title.IIF(),
                    keyword = entity.Keyword.IIF(),
                    Description = entity.Description.IIF(),
                    remark = entity.Remark.IIF(),
                    state = entity.State.ToBool()
                };
                return Success(logId, "ok", data);
            }
            catch (Exception ex)
            {
                return Error(logId, ex.Message);
            }
        }




    }
}